package com.ego.product.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ego.common.util.Result;
import com.ego.common.vo.es.SearchParam;
import com.ego.common.vo.es.SearchResult;
import com.ego.product.feign.ThirdPartyFeign;
import com.ego.product.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: ego
 * @description:
 * @author: KamTang
 * @create: 2022-12-03 17:12
 **/
@Slf4j
@Service
public class SearchServiceImpl implements SearchService {

    @Autowired
    private ThirdPartyFeign thirdPartyFeign;

    @Override
    public SearchResult search(SearchParam param) {
        SearchResult searchResult = new SearchResult();
        try {
            Result result = thirdPartyFeign.search(param);
            String jsonString = JSONObject.toJSONString(result.get("searchResult"));
            searchResult = JSONObject.parseObject(jsonString, SearchResult.class);
        } catch (Exception e) {
            log.error("调用搜索服务异常，原因 => {}", e.getMessage());
        }
        return searchResult;
    }
}
